
/*
 * Copyright 2002-2021 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 *版权所有2002-2021原作者。
 *
 *根据Apache许可证2.0版（“许可证”）许可；
 *除非符合许可证的规定，否则您不得使用此文件。
 *您可以在以下网址获取许可证副本
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 *除非适用法律要求或书面同意，否则软件
 *根据许可证分发是在“按原样”的基础上分发的，
 *无任何明示或暗示的保证或条件。
 *有关管理权限的特定语言，请参阅许可证
 *许可证下的限制。
 */

package org.springframework.format.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * Declares that a field or method parameter should be formatted as a date or time.
 *
 * <p>Supports formatting by style pattern, ISO date time pattern, or custom format pattern string.
 * Can be applied to {@link java.util.Date}, {@link java.util.Calendar}, {@link Long} (for
 * millisecond timestamps) as well as JSR-310 {@code java.time} value types.
 *
 * <p>For style-based formatting, set the {@link #style} attribute to the desired style pattern code.
 * The first character of the code is the date style, and the second character is the time style.
 * Specify a character of 'S' for short style, 'M' for medium, 'L' for long, and 'F' for full.
 * The date or time may be omitted by specifying the style character '-' &mdash; for example,
 * 'M-' specifies a medium format for the date with no time.
 *
 * <p>For ISO-based formatting, set the {@link #iso} attribute to the desired {@link ISO} format,
 * such as {@link ISO#DATE}.
 *
 * <p>For custom formatting, set the {@link #pattern} attribute to a date time pattern, such as
 * {@code "yyyy/MM/dd hh:mm:ss a"}.
 *
 * <p>Each attribute is mutually exclusive, so only set one attribute per annotation instance
 * (the one most convenient for your formatting needs).
 *
 * <ul>
 * <li>When the pattern attribute is specified, it takes precedence over both the style and ISO attribute.</li>
 * <li>When the {@link #iso} attribute is specified, it takes precedence over the style attribute.</li>
 * <li>When no annotation attributes are specified, the default format applied is style-based
 * with a style code of 'SS' (short date, short time).</li>
 * </ul>
 *
 * <h3>Time Zones</h3>
 * <p>Whenever the {@link #style} or {@link #pattern} attribute is used, the
 * {@linkplain java.util.TimeZone#getDefault() default time zone} of the JVM will
 * be used when formatting {@link java.util.Date} values. Whenever the {@link #iso}
 * attribute is used when formatting {@link java.util.Date} values, {@code UTC}
 * will be used as the time zone. The same time zone will be applied to any
 * {@linkplain #fallbackPatterns fallback patterns} as well. In order to enforce
 * consistent use of {@code UTC} as the time zone, you can bootstrap the JVM with
 * {@code -Duser.timezone=UTC}.
 *
 * @author Keith Donald
 * @author Juergen Hoeller
 * @author Sam Brannen
 * @since 3.0
 * @see java.time.format.DateTimeFormatter
 */
/**
 *声明字段或方法参数应格式化为日期或时间。
 *
 *<p>支持按样式模式、ISO日期时间模式或自定义格式模式字符串进行格式化。
 *可以应用于｛@link java.util.Date｝、｛@link java.util.Calendar｝、{@link Long｝（用于
 *毫秒时间戳）以及JSR-310{@codejava.time}值类型。
 *
 *<p>对于基于样式的格式设置，请将{@link#style}属性设置为所需的样式模式代码。
 *代码的第一个字符是日期样式，第二个字符是时间样式。
 *指定字符“S”表示短样式，“M”表示中等样式，“L”表示长样式，“F”表示完整样式。
 *可以通过指定样式字符“-”来省略日期或时间&mdash；例如
 *“M-”为没有时间的日期指定了一种中等格式。
 *
 *<p>对于基于ISO的格式，请将｛@link#ISO｝属性设置为所需的｛@link ISO｝格式，
 *例如{@link ISO#DATE}。
 *
 *＜p＞对于自定义格式，请将｛@link#pattern｝属性设置为日期-时间模式，例如
 *｛@code“yyyy/MM/dd hh:MM:ss a”｝。
 *
 *<p>每个属性都是互斥的，因此每个注释实例只设置一个属性
 *（最方便您进行格式化）。
 *
 *＜ul＞
 *＜li＞当指定pattern属性时，它优先于style和ISO属性</li>
 *＜li＞当指定{@link#iso｝属性时，它优先于样式属性</li>
 *＜li＞如果未指定注释属性，则应用的默认格式是基于样式的
 *样式代码为“SS”（短日期、短时间）</li>
 *</ul>
 *
 *<h3>时区</h3>
 *<p>每当使用{@link#style}或{@link#pattern}属性时
 *JVM的{@linkplain java.util.TimeZone#getDefault（）默认时区}将
 *在格式化｛@link java.util.Date｝值时使用。每当｛@link#iso｝
 *属性在格式化｛@link java.util.Date｝值时使用，｛@code UTC｝
 *将用作时区。相同的时区将应用于任何
 *｛@linkplain#fallbackPatterns回退模式｝。为了强制执行
 *一致使用{@code-UTC}作为时区，您可以使用
 *｛@code-Dusser.timezone=UTC｝。
 *
 *@作者Keith Donald
 *@作者Juergen Hoeller
 *@作者Sam Brannen
 *@自3.0起
 *@参见java.time.format.DateTimeFormatter
 */
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE})
public @interface DateTimeFormat {

	/**
	 * The style pattern to use to format the field or method parameter.
	 * <p>Defaults to 'SS' for short date, short time. Set this attribute when you
	 * wish to format your field or method parameter in accordance with a common
	 * style other than the default style.
	 * @see #fallbackPatterns
	 */
	/**
	 *用于格式化字段或方法参数的样式模式。
	 *<p>短日期、短时间默认为“SS”。当您
	 *希望根据常见的
	 *默认样式以外的样式。
	 *@参见#fallbackPatterns
	 */
	String style() default "SS";

	/**
	 * The ISO pattern to use to format the field or method parameter.
	 * <p>Supported ISO patterns are defined in the {@link ISO} enum.
	 * <p>Defaults to {@link ISO#NONE}, indicating this attribute should be ignored.
	 * Set this attribute when you wish to format your field or method parameter
	 * in accordance with an ISO format.
	 * @see #fallbackPatterns
	 */
	/**
	 *用于格式化字段或方法参数的ISO模式。
	 *<p>支持的ISO模式在｛@link ISO｝枚举中定义。
	 *＜p＞默认为｛@link ISO#NONE｝，表示应忽略此属性。
	 *当您希望格式化字段或方法参数时，请设置此属性
	 *根据ISO格式。
	 *@参见#fallbackPatterns
	 */
	ISO iso() default ISO.NONE;

	/**
	 * The custom pattern to use to format the field or method parameter.
	 * <p>Defaults to empty String, indicating no custom pattern String has been
	 * specified. Set this attribute when you wish to format your field or method
	 * parameter in accordance with a custom date time pattern not represented by
	 * a style or ISO format.
	 * <p>Note: This pattern follows the original {@link java.text.SimpleDateFormat} style,
	 * as also supported by Joda-Time, with strict parsing semantics towards overflows
	 * (e.g. rejecting a Feb 29 value for a non-leap-year). As a consequence, 'yy'
	 * characters indicate a year in the traditional style, not a "year-of-era" as in the
	 * {@link java.time.format.DateTimeFormatter} specification (i.e. 'yy' turns into 'uu'
	 * when going through a {@code DateTimeFormatter} with strict resolution mode).
	 * @see #fallbackPatterns
	 */
	/**
	 *用于格式化字段或方法参数的自定义模式。
	 *＜p＞默认为空字符串，表示没有自定义模式字符串
	 *指定。当您希望格式化字段或方法时设置此属性
	 *参数符合自定义日期-时间模式，而不是由表示
	 *样式或ISO格式。
	 *<p>注意：此模式遵循原始的{@link java.text.SimpleDateFormat}样式，
	 *正如Joda Time所支持的那样，具有针对溢出的严格解析语义
	 *（例如，对于非闰年，拒绝2月29日的数值）。因此，“yy”
	 *字符在传统风格中表示年份，而不是像在
	 *｛@link java.time.format.DateTimeFormatter｝规范（即“yy”变为“uu”
	 *当通过具有严格分辨率模式的{@code DateTimeFormatter}时）。
	 *@参见#fallbackPatterns
	 */
	String pattern() default "";

	/**
	 * The set of custom patterns to use as a fallback in case parsing fails for
	 * the primary {@link #pattern}, {@link #iso}, or {@link #style} attribute.
	 * <p>For example, if you wish to use the ISO date format for parsing and
	 * printing but allow for lenient parsing of user input for various date
	 * formats, you could configure something similar to the following.
	 * <pre style="code">
	 * {@literal @}DateTimeFormat(iso = ISO.DATE, fallbackPatterns = { "M/d/yy", "dd.MM.yyyy" })
	 * </pre>
	 * <p>Fallback patterns are only used for parsing. They are not used for
	 * printing the value as a String. The primary {@link #pattern}, {@link #iso},
	 * or {@link #style} attribute is always used for printing. For details on
	 * which time zone is used for fallback patterns, see the
	 * {@linkplain DateTimeFormat class-level documentation}.
	 * <p>Fallback patterns are not supported for Joda-Time value types.
	 * @since 5.3.5
	 */
	/**
	 *在解析失败时用作回退的自定义模式集
	 *主｛@link#pattern｝、｛@link#iso｝或｛@link#style｝属性。
	 *＜p＞例如，如果您希望使用ISO日期格式进行解析和
	 *打印，但允许对不同日期的用户输入进行宽松的解析
	 *格式，您可以配置类似于以下内容的内容。
	 *<pre-style=“code”>
	 *｛@literal@｝DateTimeFormat（iso=iso.DATE，fallbackPatterns=｛“M/d/yy”，“dd.MM.yyyy”｝）
	 *</pre>
	 *＜p＞回退模式仅用于解析。它们不用于
	 *将该值打印为字符串。主{@link#模式}、{@link#iso}，
	 *或｛@link#style｝属性始终用于打印。有关的详细信息
	 *哪个时区用于回退模式，请参阅
	 *｛@linkplain DateTimeFormat类级文档｝。
	 *＜p＞Joda Time值类型不支持回退模式。
	 *@自5.3.5起
	 */
	String[] fallbackPatterns() default {};


	/**
	 * Common ISO date time format patterns.
	 */
	/**
	 *常见的ISO日期时间格式模式。
	 */
	enum ISO {

		/**
		 * The most common ISO Date Format {@code yyyy-MM-dd} &mdash; for example,
		 * "2000-10-31".
		 */
		/**
		 *最常见的ISO日期格式｛@code yyyy-MM-dd｝&mdash；例如
		 * "2000-10-31".
		 */
		DATE,

		/**
		 * The most common ISO Time Format {@code HH:mm:ss.SSSXXX} &mdash; for example,
		 * "01:30:00.000-05:00".
		 */
		/**
		 *最常见的ISO时间格式{@code HH:mm:ss.SSSXXX}&mdash；例如
		 * "01:30:00.000-05:00".
		 */
		TIME,

		/**
		 * The most common ISO Date Time Format {@code yyyy-MM-dd'T'HH:mm:ss.SSSXXX}
		 * &mdash; for example, "2000-10-31T01:30:00.000-05:00".
		 */
		/**
		 *最常见的ISO日期-时间格式｛@code yyyy-MM-dd-'T'HH:MM:ss.SSSXXX｝
		 *&mdash；例如，“2000-10-31T01:30:00.000-05:00”。
		 */
		DATE_TIME,

		/**
		 * Indicates that no ISO-based format pattern should be applied.
		 */
		/**
		 *指示不应应用基于ISO的格式模式。
		 */
		NONE
	}

}
